#include "db.h"
int main()
{
char datetime[140];	
time_t rawtime;
  struct tm * timeinfo;

  time ( &rawtime );
  timeinfo = localtime ( &rawtime );
char  result[1024*1024];//1M
char buf[80]; 
char number[16]; 
char lastterm[20];
  sprintf (datetime, "//This is Create at %s \n", asctime (timeinfo) );	
	strcpy (result,datetime);
	strcat (result,"G_BALLS=[\n");

   if(rc!=SQLITE_OK)
    {
    printf("%s ",zErrMsg);
    }	
	query(QUERY_DB);
	
int i=0;
for( i=1;i<=nrow;i++)//line,注意，recoreds包含了列名字
   {
//   printf(".....1\n");	

   	strcpy(buf,"[");
 int j=0;
    for( j=0;j<ncol;j++)
   {
   	if(j==0)
   		{
   	sprintf(lastterm,"'%s'",(records[i*ncol]));			
   }
   	
				 	if(j==0 || j==1) //term and date time
				 		{
						sprintf(number,"'%s'",(records[i*ncol+j]));				 			
			      strcat(buf,number);
			      }
	//printf(".....2\n");		      
				 	if(j>1) //term and date time
				 		{
			      sprintf(number,"'%02s'",(records[i*ncol+j]));
			      strcat(buf,number);
			      }
			      if(j<(ncol-1))
		      	 {
			           strcat(buf,",");
		        }
   }
	strcat(buf,"],\n");		     
  strcat (result,buf); 				 
   
      }	
strcat (result,"];\n"); 
strcat (result,"LAST_TERM=");
strcat (result,lastterm);
strcat (result,";\n"); 
printf("%s",result);
}
